import { emojiPaths } from "./emoji"

export function typeToValue(type) {
  return {
    text: 0,
    image: 1,
    'red-envelope': 2,
    voice: 3
  }[type]
}

export function valueToType(value) {
  return {
    0: 'text',
    1: 'image',
    2: 'red-envelope',
    3: 'voice'
  }[value]
}


export function convertMessageTextToRich(text) {
  return text.replace(/\[(.*?)\]/g, (match, p1) => {
    return createEmojiElment(p1)
  })
}

export function createEmojiElment(name, element = false, regx = false) {
  const img = `<img class="emoji" src="${regx ? '\\/emoji\\/(.*?)\\.gif' : emojiPaths[name]}">`
  if (element) {
    const container = document.createElement('div')
    container.innerHTML = img
    return container.children[0]
  }
  return img
}
